﻿//
// Created by gogoqiu on 2022/1/11.
//

#ifndef RAPIDSVN_CMAKE_MAINDIALOG_H
#define RAPIDSVN_CMAKE_MAINDIALOG_H

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <wx/listbox.h>
#include <wx/filepicker.h>
#include <mysql.h>

#include "data/Preference.h"
#include "PreferenceScreen.h"
#include "MyTagApp.h"
#include "ids.h"

//

class PreferenceAdapter;
class DelayThread;
//struct Item;

class MainDialog : public wxFrame
{
public:
    /*
     * data update
     * objects
     * View
     * getCurrentValue
     * load the table
     * build the view items
     * dialog
     * 只有value是变化的
     */
    MainDialog( wxWindow *parent, MyTagApp * _myTagApp );
    MainDialog( MyTagApp* _myTagApp, const wxString & title, const wxLocale & locale );
    ~MainDialog() override;

    void post();
    WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) override ;
private:
    MyTagApp * myTagApp;
    vector<wxPanel*> panels;
    PreferenceAdapter *mPreferenceAdapter;
    bool should_delete_file;

    void buildMenu();
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void OnFilePickerChange(wxFileDirPickerEvent& event);

    void BuildView( );
    void addMySqlLog( wxString log );

    void OnRunDelay( wxCommandEvent& event );
    void OnStartPost( wxCommandEvent& event );
    void OnCBFileDelete( wxCommandEvent& event );

    int idx;
    void request();
    /*
     * layout:
     *  list: sizeBox(v)
     *      panel
     *          sizeBox(v)
     *              //sizeBox(h)
     *                  title//, wxSpace, input:value
     *              statusCtrl
     */
    wxPanel *m_panel;
    //listBox sizer
    wxBoxSizer *panelRootBoxSizer;
    wxBoxSizer *dialogRootBoxSizer;
    wxScrolledWindow* m_listbox;
    wxTextCtrl* m_logBox;
    wxFilePickerCtrl* m_filePicker1;
    wxCheckBox *cb_isDelete;
    wxTimer *m_timer;
    //void OnClickItem(wxCommandEvent& event);
    virtual void OnClickItem( wxMouseEvent& event );

    void OnClose( wxCloseEvent&  event );

    void OnActionEvent(wxCommandEvent &event);
    void OnTimer( wxTimerEvent& event );
private:

    wxGauge *m_gauge1;
    wxButton *test_delay_button;
    wxButton *start_post_button;
    //wxThread *networkMonitor;
    //
    wxThread *postFileWorker;
    DelayThread* delayThread;

    MYSQL *conn_ptr;

    void addLog( const wxString& log );
    void addEventLog( const wxString& log );
    //Item* item;
DECLARE_EVENT_TABLE()
};
enum
{
    ID_Hello = 1
};

#endif //RAPIDSVN_CMAKE_MAINDIALOG_H
